<?php
$result = array();

$result["backup"] = ["target" => "OK", "actual" => "OK", "msg" => "OK"];
$rootDir=$_SERVER["DOCUMENT_ROOT"];
$backup=checkIsWriteable($rootDir."/backup");
if(!$backup){
    $result["backup"] = ["target" => "OK", "actual" => "No", "msg" => "backup目录不可写"];
}
$result["upload"] = ["target" => "OK", "actual" => "OK", "msg" => "OK"];
$upload=checkIsWriteable($rootDir."/upload");
if(!$upload){
    $result["backup"] = ["target" => "OK", "actual" => "No", "msg" => "upload目录不可写"];
}
function checkIsWriteable($file) {
    if (is_dir($file)){
        $dir = $file;
        if ($fp = @fopen("$dir/test.txt", 'w')) {
            @fclose($fp);
            @unlink("$dir/test.txt");
            $writeable = 1;
        } else {
            $writeable = 0;
        }
    } else {
        if ($fp = @fopen($file, 'a+')) {
            @fclose($fp);
            $writeable = 1;
        } else {
            $writeable = 0;
        }
    }
    return $writeable;
}
?>
<!DOCTYPE html >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>LeeCms系统安装</title>
    <link rel="stylesheet" href="/<?php echo $basepath ?>/install/assert/install.css"/>
    <script type="text/javascript" src="/<?php echo $basepath ?>/assert/js/jquery.js"></script>
</head>
<body>
<div class="header">
    <div class="logo">LeeCms</div>
    <div class="step">
        <div class="line"></div>
        <ul class="step_num">
            <li class=""><span class="num">1</span>
                <p class="name">阅读安装协议</p></li>
            <li class=""><span class="num">2</span>
                <p class="name">检测安装环境</p></li>
            <li class="current"><span class="num">3</span>
                <p class="name">可写检测</p></li>
            <li class=""><span class="num">4</span>
                <p class="name">开始安装</p></li>
            <li class=""><span class="num">5</span>
                <p class="name">完成安装</p></li>
        </ul>

    </div>
</div>
<div class="content">
    <table border="1" cellpadding="true" cellspacing="true">
        <thead>
        <tr>
            <th>检查目录</th>
            <th>LeeCms期望结果</th>
            <th>系统实际检测结果</th>
            <th>描述</th>
        </tr>
        </thead>
        <?php
        $flag = true;
        foreach ($result as $key => $val) {
            if ($val["msg"] != "OK") {
                $flag = false;
            }
            ?>
            <tr>
                <td><?php echo $key ?></td>
                <td width="120"><?php echo $val["target"] ?></td>
                <td style="width:120px;font-weight: bold;<?php echo $val["msg"] != "OK" ? "color:red" : "color:green"; ?>"><?php echo $val["actual"] ?></td>
                <td><?php echo $val["msg"] ?></td>
            </tr>
        <?php } ?>

        </tbody>
    </table>
</div>
<script type="text/javascript">
    function submit_next() {
        let flag = "<?php echo $flag;?>";
        if (flag !== "1"&&flag!=="true") {
            alert("当前环境存在不可写目录,请先设置目录为可写.");
            return false;
        }
        window.location.href = "?step=step4";
    }
</script>
<div class="btn_wrap">
    <input name=""
           type="button"
           class="next_btn"
           value="下一步"
           onclick="submit_next()"/><input
            name="" type="button" class="prev_btn" value="上一步" onclick="window.location.href='?step=step2'"/>
    <div class="cl"></div>
</div>
<div class="footer">Powered By LeeCms 版权所有 &copy; 2020-2022, All right reserved.</div>
</body>
</html>